package com.cloudminga.gui;


import com.globussoft.amazons3.MultithreadingUpload;
import com.globussoft.amazons3.UploadFile;
import com.globussoft.xml.CreatXMLFile;
import com.globussoft.xml.SettingsXml;
//import com.pomblast.persistentlayer.User;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.text.Normalizer.Form;
import java.util.HashMap;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.xml.parsers.ParserConfigurationException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Gui_6.java
 *
 * Created on Dec 17, 2009, 12:49:35 PM
 */

/**
 *
 * @author jyoti
 */
public class Config_6_complete extends javax.swing.JDialog {

    /** Creates new form Gui_6 */
     Config_5_speed configSpeed;
     private String projectName="";
    public Config_6_complete(java.awt.Frame parent, boolean modal,Config_5_speed configSpeed) {
        super(parent, modal);
        this.setDefaultCloseOperation(Config_6_complete.DISPOSE_ON_CLOSE);
        Dimension dimension = new Dimension(600, 500);
        this.configSpeed=configSpeed;
        initComponents();
        projectName=SettingsXml.getProjectName();
        this.setTitle("Welcome to "+projectName+" Backup Wizard Configuration");
        jLabel4.setText("You have comleted the "+projectName+" Wizard.");
        initial_bakupidle_RadioButton.setText("Let's "+projectName+" start the initial backup automatically  when my computer is idle.");
        setSize(600, 500);
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        int x = (toolkit.getScreenSize().width - getWidth()) / 2;
        int y = (toolkit.getScreenSize().height - getHeight()) / 2;
        setResizable(true);
        setLocation(x, y);
        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
      
      
        initial_backupnow_RadioButton.setSelected(true);
         try {
            /* code to set the look and feel according to the native operating system */

            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            SwingUtilities.updateComponentTreeUI(this);

        } catch (Exception e) {
            System.out.println("Problem in setting look and feel");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        backCompleteButton = new javax.swing.JButton();
        cancelCompleteButton = new javax.swing.JButton();
        finishCompleteButton = new javax.swing.JButton();
        initial_backupnow_RadioButton = new javax.swing.JRadioButton();
        initial_bakupidle_RadioButton = new javax.swing.JRadioButton();
        expertmode_RadioButton = new javax.swing.JRadioButton();
        label_image = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        label_Logo = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("");
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        backCompleteButton.setText("Back");
        backCompleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backCompleteButtonActionPerformed(evt);
            }
        });
        getContentPane().add(backCompleteButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 400, -1, -1));

        cancelCompleteButton.setText("Cancel");
        cancelCompleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelCompleteButtonActionPerformed(evt);
            }
        });
        getContentPane().add(cancelCompleteButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 400, -1, -1));

        finishCompleteButton.setText("Finish ");
        finishCompleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                finishCompleteButtonActionPerformed(evt);
            }
        });
        getContentPane().add(finishCompleteButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 400, -1, -1));

        initial_backupnow_RadioButton.setText("I'd like to start my initial backup right now.");
        initial_backupnow_RadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                initial_backupnow_RadioButtonActionPerformed(evt);
            }
        });
        getContentPane().add(initial_backupnow_RadioButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 340, -1, -1));

        initial_bakupidle_RadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                initial_bakupidle_RadioButtonActionPerformed(evt);
            }
        });
        getContentPane().add(initial_bakupidle_RadioButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 320, 430, -1));

        expertmode_RadioButton.setText("I'd like to continue configuring my backup in expert mode.");
        expertmode_RadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                expertmode_RadioButtonActionPerformed(evt);
            }
        });
        getContentPane().add(expertmode_RadioButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 300, -1, -1));

        label_image.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/config_6_complete.jpg"))); // NOI18N
        label_image.setText("jLabel3");
        getContentPane().add(label_image, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, 160, -1));

        jLabel3.setFont(new java.awt.Font("Arial", 0, 36));
        jLabel3.setForeground(new java.awt.Color(51, 51, 255));
        jLabel3.setText("Congratulations!");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 130, 270, -1));

        jLabel4.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(51, 51, 51));
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 180, 240, -1));

        jPanel1.setBackground(new java.awt.Color(204, 204, 204));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        label_Logo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/logo_2.png"))); // NOI18N
        label_Logo.setText("jLabel5");
        jPanel1.add(label_Logo, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 10, 55, 55));
        label_Logo.getAccessibleContext().setAccessibleName("label_Logo");

        jLabel1.setFont(new java.awt.Font("Arial", 0, 18));
        jLabel1.setForeground(new java.awt.Color(51, 51, 255));
        jLabel1.setText("Setup Completed...");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 160, 20));

        jLabel2.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel2.setForeground(new java.awt.Color(51, 51, 255));
        jLabel2.setText("You have completed the configuration wizard.");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 40, 260, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 550, 70));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelCompleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelCompleteButtonActionPerformed
    this.dispose();
}//GEN-LAST:event_cancelCompleteButtonActionPerformed

    private void initial_bakupidle_RadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_initial_bakupidle_RadioButtonActionPerformed
        // TODO add your handling code here:
        initial_bakupidle_RadioButton.setSelected(true);
        if(initial_bakupidle_RadioButton.isSelected()==true)
        {
            expertmode_RadioButton.setSelected(false);
            initial_backupnow_RadioButton.setSelected(false);
        }
     
}//GEN-LAST:event_initial_bakupidle_RadioButtonActionPerformed

    private void finishCompleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finishCompleteButtonActionPerformed
        // TODO add your handling code here:
         boolean expertmode=false,initbackupidle=false,initbackupnow=false;
        if(expertmode_RadioButton.isSelected()==true)
        {
            expertmode=true;
        }
         if(initial_bakupidle_RadioButton.isSelected()==true)
        {
            initbackupidle=true;
        }
         if(initial_backupnow_RadioButton.isSelected()==true)
        {
            initbackupnow=true;
        }
         SettingsXml setting=new SettingsXml();
         setting.setexpertmode(expertmode);
         setting.setinitialidle(initbackupidle);
         setting.setinitialnow(initbackupnow);
        try {
            setting.writeGeneralXml("settings.xml");
          
        } catch (ParserConfigurationException ex) {
           // Logger.getLogger(Config_6_complete.class.getName()).log(Level.SEVERE, null, ex);
        }
         if(initbackupnow){
            new Thread(){public void run()
            {
            // UploadFile uploadFile=new UploadFile();
             MultithreadingUpload multiThreadingObj= new MultithreadingUpload("Upload", System.getProperty("user.home")+"/"+projectName+"/BackUpSet.xml", "Manual");
             HashMap map = new CreatXMLFile().ReadXmlFile(System.getProperty("user.home")+"/"+projectName+"/BackUpSet.xml",true);
            // uploadFile.uploadFiles(System.getProperty("user.home")+"/"+projectName+"/BackUpSet.xml",map,"BackupSet");
             multiThreadingObj.uploadFile(map,10);
            }
         }.start();
         }
         
         this.dispose();
        //  MainForm frmMain = new MainForm();
        //  frmMain.setVisible(true);
          
       // User con=new User();
       // con.ConfigureComplete(expertmode,initbackupidle,initbackupnow);
}//GEN-LAST:event_finishCompleteButtonActionPerformed

    private void backCompleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backCompleteButtonActionPerformed
        // TODO add your handling code here:
         this.setVisible(false);
         configSpeed.setVisible(true);
        // this.dispose();
      //  new Config_5_speed(new javax.swing.JFrame(), true,this).setVisible(true);
}//GEN-LAST:event_backCompleteButtonActionPerformed

    private void expertmode_RadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_expertmode_RadioButtonActionPerformed
        // TODO add your handling code here:
        expertmode_RadioButton.setSelected(true);
        if(expertmode_RadioButton.isSelected()==true)
        {
            initial_bakupidle_RadioButton.setSelected(false);
            initial_backupnow_RadioButton.setSelected(false);
        }
     
}//GEN-LAST:event_expertmode_RadioButtonActionPerformed

    private void initial_backupnow_RadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_initial_backupnow_RadioButtonActionPerformed
        // TODO add your handling code here:
        initial_backupnow_RadioButton.setSelected(true);
         if(initial_backupnow_RadioButton.isSelected()==true)
        {
            expertmode_RadioButton.setSelected(false);
            initial_bakupidle_RadioButton.setSelected(false);
        }
     
    }//GEN-LAST:event_initial_backupnow_RadioButtonActionPerformed

    /**
    * @param args the command line arguments
    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                Config_6_complete dialog = new Config_6_complete(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backCompleteButton;
    private javax.swing.JButton cancelCompleteButton;
    private javax.swing.JRadioButton expertmode_RadioButton;
    private javax.swing.JButton finishCompleteButton;
    private javax.swing.JRadioButton initial_backupnow_RadioButton;
    private javax.swing.JRadioButton initial_bakupidle_RadioButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel label_Logo;
    private javax.swing.JLabel label_image;
    // End of variables declaration//GEN-END:variables

}
